<template>
  <el-table
    :data="orderlist"
    style="width: 100%">
    <el-table-column
      label="下单时间"
      width="150">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.time }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="陪玩ID"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.pid }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="数量/小时"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.num }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="订单总价/元"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.price }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="支付状态"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.state }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="订单状态"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.o }}</span>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          v-show="show(scope.row.o)"
          size="mini"
          type="danger"
          @click="handleDelete(scope.row.id)">结束订单</el-button
          v-show>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
  import axios from 'axios'
  export default {
    data() {
      return {
        orderlist:[],
        user:{},
        id:'',
        search: ''
      }
    },
    created() {
      this.getUser();
    },
    mounted() {
    },
    methods: {
      show:function(o){
        if(o=='已完成'){
          return false;
        }else {
          return true;
        }
      },
      getUser:function () {
        var user=sessionStorage.getItem("user");
        axios.post("api/play/findOne",{playname:user}).then(res=>{
            this.user=res.data.data;
            this.id=this.user.id;
            axios.post("api/order/playAll",{pid:this.id}).then(res=>{
              if (res.data.code==200){
                this.orderlist=res.data.data;
              }
            })
        })
      },
      handleDelete(oid) {
        axios.post("api/play/upo",{id:oid}).then(res=>{
          if (res.data.code==200){
            location.reload();
            alert("订单已结束")
          }else{
            alert("无法结束请重试")
          }
        })
      }
    },
  }
</script>

<style scoped>

</style>
